import {Button,Modal} from "antd";
import {ExclamationCircleOutlined} from "@ant-design/icons";
import {commentDeleteOneApi,commentEditOneApi} from "../../../api";
export function useCommentBtns(getTableData) {
    const { confirm } = Modal
    const commentBtns = row => {
        const { comment_id,comment_status } = row
        const handleStatus = status =>{
            confirm({
                icon: <ExclamationCircleOutlined />,
                title: '提示',
                content: `确定要${ status ? '打开': '屏蔽' }该评论吗`,
                centered: true,
                onOk() {
                    commentEditOneApi({comment_id,comment_status:status})
                        .then(res => {
                            if(res.success) {
                                window.$message.success(`${ status ? '打开': '屏蔽' }成功`)
                            }
                        }).catch(e => window.$message.error(e)).finally(_ => getTableData())
                }
            })
        }
        const handleDeleteComment = () => {
            confirm({
                icon: <ExclamationCircleOutlined />,
                title: '提示',
                content: '确认要删除该评论吗？',
                centered: true,
                onOk() {
                    commentDeleteOneApi({ comment_id })
                        .then(res => {
                            if(res.success) {
                                window.$message.success(res.msg)
                            }
                        }).catch(e => window.$message.error(e)).finally(_ => getTableData())
                }
            })
        }
        return (
            <div className="comment-btns">
                { !!comment_status && <Button className="btn" size="small" type="primary" onClick={() => handleStatus(0)}>屏蔽</Button> }
                { !comment_status && <Button className="btn" size="small" type="primary" onClick={() => handleStatus(1)}>打开</Button>}
                { !comment_status && <Button onClick={handleDeleteComment} className="btn" size="small" danger type="primary">删除</Button>}
            </div>
        )
    }
    return{
        commentBtns
    }
}
